﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WMH_Project
{
  public class Graph
    {
        private int numberOfX;

        public int NumberOfX
        {
            get { return numberOfX; }
            set { numberOfX = value; }
        }
        private int numberOfY;

        public int NumberOfY
        {
            get { return numberOfY; }
            set { numberOfY = value; }
        }

      
        public Graph(int x, int y, int maxCost)
        {
            NumberOfX = x;
            numberOfY = y;
            Random r = new Random();
            nodesX = new Node[numberOfX];
            nodesY = new Node[numberOfY];

            for (int i = 0; i < numberOfX; i++)
            {
                List<Edge> le = new List<Edge>();
                for (int j = 0; j < NumberOfY; ++j)
                {
                    if(r.NextDouble()<0.5)
                        le.Add(new Edge(r.Next(maxCost), j));
                }
                if(le.Count==0)
                    le.Add(new Edge(r.Next(maxCost), r.Next(NumberOfY)));

               // le.Sort(Edge.compare);

                nodesX[i] = new NodeX(le);
            }

            for (int i = 0; i < numberOfY; i++)
                nodesY[i] = new NodeY(null);  
        }


      public Graph(System.IO.StreamReader sr)
      {

          String line = sr.ReadLine();
          String[] numbers = line.Split(' ');

          numberOfX = int.Parse(numbers[0]);
          numberOfY = int.Parse(numbers[1]);
          nodesX = new Node [numberOfX];
          nodesY = new Node [numberOfY];

          for (int i = 0; i < numberOfX; i++)
            nodesX[i] = new NodeX(sr);
          for (int i = 0; i < numberOfY; i++)
            nodesY[i] = new NodeY(sr);           
      }
     override public String ToString()
     {
         String ret;
         ret = numberOfX.ToString() + ' ' + numberOfY.ToString() + Environment.NewLine;
         for (int i = 0; i < numberOfX; i++)
            ret += nodesX[i].ToString();
         for (int i = 0; i < numberOfY; i++)
            ret += nodesY[i].ToString();

         return ret;
     }
     private Node[] nodesX;

     public Node[] NodesX
     {
         get { return nodesX; }
         set { nodesX = value; }
     }
     private Node[] nodesY;

     public Node[] NodesY
     {
         get { return nodesY; }
         set { nodesY = value; }
     }

    }


}
